#include <udt_interface.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>

UDTDataLinkSet dataSet;

int max_attrib_used = 3;
int max_depth = 25;
double stop_criteria = 0.1;
double min_entropy_gain = -100;

char filePath[] = "../data/in/";
char fileExtension[] = "_uncertain.txt";


typedef struct _TIMINGINFO
{
    LARGE_INTEGER ti_start, ti_end;
} TIMINGINFO;


void TimerStart(TIMINGINFO * pti)
{
    QueryPerformanceCounter(&(pti->ti_start));   
}

void TimerStop(TIMINGINFO * pti)
{
    QueryPerformanceCounter(&(pti->ti_end));
}

double TimerRead(TIMINGINFO * pti)
{
    LARGE_INTEGER freq;
    QueryPerformanceFrequency(&freq);
    return ((double)(pti->ti_end.QuadPart - pti->ti_start.QuadPart)) /
        freq.QuadPart * 1000.0;
}


void process(char *fileName)
{
    double overall_precision, time;
    TIMINGINFO ti;

    printf("Processing: %s\n", fileName);
    udt_inputData(fileName, &dataSet);

    TimerStart(&ti);
    overall_precision = udt_testKFold(&dataSet, 5);
    TimerStop(&ti);

    printf("Overall Precision: %lf\n", overall_precision);
    time = TimerRead(&ti);
    printf("Elapsed time %lf ms, (%lf ms per fold)\n", time, time/5);
};

int main(int argc, char **argv)
{
    int i = 2;
    char fullName[250];
    strcpy(fullName, filePath);
    strcat(fullName, argv[1]);
    strcat(fullName, fileExtension);
    

    while ( i < argc) {
        if (strcmp(argv[i], "--depth") == 0) {
            i++;
            sscanf(argv[i], "%d", &max_depth);
            printf("Max Depth: %d\n", max_depth);
        }
        else if (strcmp(argv[i], "--attrib") == 0) {
            i++;
            sscanf(argv[i], "%d", &max_attrib_used);            
            printf("Max Attrib Used: %d\n", max_attrib_used);
        }
        else if (strcmp(argv[i], "--stop") == 0) {
            i++;
            sscanf(argv[i], "%lf", &stop_criteria);            
            printf("Stop Criteria: %lf\n", stop_criteria);
        };

        i++;
    };    

    process(fullName);
    return 0;
};    

